<template>
	<view class="searchResult">
		<view class="search">
			<u-search placeholder="输入商家名称" v-model="searchValue" @search="search" :show-action="false"></u-search>
		</view>
		<!-- 综合排序,销量优先,速度优先 -->
		<scroll-view ref="tabbar1" id="tab-bar" class="tab-bar" :scroll="false" :scroll-x="true" :show-scrollbar="false"
			:scroll-into-view="`id` + current">
			<view class="tab-list">
				<view :id="`id` + index" class="tab-item-wrapper" v-for="(item, index) in tagList" :key="index">
					<view class="tab-item" :class="{ 'item-active': current === index }" @click="tabsChange(index)">
						<view>
							{{ item }}
						</view>
					</view>
				</view>
			</view>
		</scroll-view>
		<view class="">
			<ShopList :list="shopLists"></ShopList>
		</view>

		<view class="icon-box-img" v-if="shopLists.length == 0">
			<img src="../../static/index/noResult.png" alt="">
			<view class="text">
				未搜索到相关产品
			</view>
		</view>
	</view>
</template>

<script>
import ShopList from '@/components/ShopList/index.vue'

import navbar from '../../components/navBar/navBar.vue'
// import searchInput from '../../components/search/searchInput.vue'
const $api = require('../../utils/request.js').API
export default {
	data() {
		return {
			title: '搜索',
			textObj: '',
			searchValue: '',
			selectedItem: 0,
			// 因为内部的滑动机制限制，请将tabs组件和swiper组件的current用不同变量赋值
			current: 0, // tabs组件的current值，表示当前活动的tab选项
			swiperCurrent: 0, // swiper组件的current值，表示当前那个swiper-item是活动的
			tagList: ["综合排序", "销量优先", "速度优先"],
			shopList: [],	// 店铺列表
			shopLists: [],
			describe: [],
			nav_id: null,
			longitude: null, //经度
			latitude: null, //纬度
		}
	},
	components: {
		navbar,
		ShopList
	},
	onLoad(options) {
		this.getLocationsFun();
		this.searchValue = options.value
		if (options.item) {
			this.nav_id = JSON.parse(options.item).nav_id
		}
		// this.commodityList()
		if (options.source == 0) {
			uni.setNavigationBarTitle({
				title: '餐食'
			})
		} else if (options.source == 1) {
			uni.setNavigationBarTitle({
				title: '水果'
			})
		} else if (options.source == 2) {
			uni.setNavigationBarTitle({
				title: '奶茶'
			})
		} else if (options.source == 3) {
			uni.setNavigationBarTitle({
				title: '超市'
			})
		}
	},
	onShow() {
		// this.getList()
	},
	methods: {
		getLocationsFun() {
			var that = this;
			uni.getLocation({
				type: 'wgs84',
				success: function (res) {
					that.longitude = res.longitude;
					that.latitude = res.latitude;
					that.storeList(that.searchValue)

				}
			});
		},
		storeList(searchValue, order) {
			$api.postStoreList({
				keyword: searchValue,
				order: order,
				nav_id: this.nav_id,
				lat: this.latitude,//  纬度
				lng: this.longitude, //  经度
			}).then(res => {


				this.shopLists = res.data.data.list.map(item => {
					item.searchGoods = [...item.searchGoods, ...item.hotGoods]
					item.hotGoods = item.searchGoods.slice(0, 3) || []
					return item
				})
			})
		},
		// commodityList(){
		// 	$api.postCommodityList({
		// 		site_id: 2
		// 	}).then(res => {	
		// 		this.describe = res.data.data
		// 	})
		// },
		search(val) {
			this.storeList(val)
		},
		selectItem(index) {
			this.selectedItem = index;
		},
		// tabs通知swiper切换
		tabsChange(index) {
			this.current = index;
			this.swiperCurrent = index;
			if (index == 0) {
				this.storeList(this.searchValue)
			} else if (index == 1) {
				this.storeList(this.searchValue, 'shop_sales')
			} else if (index == 2) {
				this.storeList(this.searchValue, 'distance')
			}
		},
		Jumpshop(item) {
			uni.navigateTo({
				url: '../../pages_order/order/order?site_id=' + item.site_id
			});
		},
		JumpCommodityDetails(i) {
			uni.navigateTo({
				url: `../../pages/Productdetails/Productdetails?source=${0}&sku_id=${i.sku_id}&site_id=${i.site_id}`
			})
		},
		// swiper-item左右移动，通知tabs的滑块跟随移动
		transition(e) {
			let dx = e.detail.dx;
			// this.$refs.uTabs.setDx(dx);
		},
		// 由于swiper的内部机制问题，快速切换swiper不会触发dx的连续变化，需要在结束时重置状态
		// swiper滑动结束，分别设置tabs和swiper的状态
		animationfinish(e) {
			let current = e.detail.current;
			// this.$refs.uTabs.setFinishCurrent(current);
			this.swiperCurrent = current;
			this.current = current;
		},
		// scroll-view到底部加载更多
		onreachBottom() {

		}
	}
}
</script>

<style lang="less" scoped>
.search {
	padding-top: 21rpx;
}

.tab-bar {
	// height: 44rpx;
	height: 70rpx;
	margin-top: 30rpx;

	.tab-list {
		display: flex;
		justify-content: space-between;
		align-items: center;
		// height: 100%;
		padding: 0 42rpx;

		.tab-item-wrapper {
			display: flex;
			flex-shrink: 0;
			justify-content: center;
			// align-items: flex-end;
			align-items: center;

			// height: 100%;
			.tab-item {
				display: flex;
				align-items: center;
				justify-content: center;
				flex-direction: column;
				width: 144rpx;
				height: 44rpx;
				font-size: 28rpx;
				font-family: PingFang SC;
				font-weight: 500;
				color: #3F3F3F;
				// line-height: 70rpx;

				&.item-active {
					font-size: 28rpx;
					font-family: PingFang SC;
					font-weight: 500;
					color: #F14500;
					line-height: 70rpx;
				}
			}
		}

	}
}

.header {
	width: 100%;
	position: fixed;
	top: 10rpx;
	left: 0;
	// height: 150rpx;
	background-size: 100% 100%;
	background-repeat: no-repeat;
	background-position: 0 0;
	z-index: 9999;
}

.icon-box-img {
	display: flex;
	flex-direction: column;
	align-items: center;
	justify-content: center;
	margin-top: 80rpx;

	img {
		width: 343rpx;
		height: 306rpx;
	}

	image {
		width: 343rpx;
		height: 306rpx;
	}

	.text {
		margin-top: 35rpx;
		font-size: 30rpx;
		font-family: PingFang SC;
		font-weight: 400;
		color: #C3C4C4;
		line-height: 30rpx;
	}
}

.icon-box-img img {
	width: 343rpx;
	height: 306rpx;
}

.text {
	margin-top: 35rpx;
	font-size: 30rpx;
	font-family: PingFang SC;
	font-weight: 400;
	color: #C3C4C4;
	line-height: 30rpx;
}

.describeContent {
	display: flex;
	flex-direction: column;
	align-items: flex-start;
	justify-content: space-around;
	margin: 0 3px;
	padding: 6rpx;
	min-width: 157rpx;
	height: 186rpx;
	background: #FFFFFF;
	border: 1px solid #F9F9F9;
	border-radius: 10rpx;
}

.describe {
	width: 100%;
	height: 35rpx;
	margin-top: 5rpx;
	font-size: 18rpx;
	font-family: PingFang SC;
	font-weight: 500;
	color: #161415;
	overflow: hidden;
	text-overflow: ellipsis;
	white-space: nowrap;
}

.price {
	font-size: 20rpx;
	font-family: PingFang SC;
	font-weight: 500;
	color: #3A3A3A;
}

.pri_t {
	margin-left: 8rpx;
	font-size: 18rpx;
	font-family: PingFang SC;
	font-weight: 400;
	text-decoration: line-through;
}

img {
	width: 142rpx;
	height: 146rpx;
	border-radius: 10rpx;
}

image {
	width: 142rpx;
	height: 146rpx;
	border-radius: 10rpx;
}

.shopText {
	display: flex;
	flex-direction: column;
	justify-content: space-between;
	margin-left: 24rpx;
}

.shopName {
	font-size: 30rpx;
	font-family: PingFang SC;
	font-weight: 500;
	color: #161415;
}

.shopNum,
.shopMoney {
	font-size: 20rpx;
	font-family: PingFang SC;
	font-weight: 400;
	color: #989898;
}

.shopManjian {
	height: 32rpx;
	border: 1px solid #EB1D1D;
	border-radius: 5rpx;
	font-size: 18rpx;
	text-align: center;
	font-family: PingFang SC;
	font-weight: 400;
	color: #E31212;
	margin-right: 10rpx;
	padding: 0 10rpx;
}

.school {
	min-width: 87rpx;
	text-align: center;
	height: 29rpx;
	line-height: 29rpx;
	background: #F14500;
	border-radius: 5rpx;
	font-size: 16rpx;
	font-family: PingFang SC;
	font-weight: 400;
	color: #FFFFFF;
}

.long {
	margin-top: 50rpx;
	font-size: 20rpx;
	font-family: PingFang SC;
	font-weight: 400;
	color: #989898;
}

.topRight {
	display: flex;
	flex-direction: column;
	margin-right: 25rpx;
}

.topLeft {
	display: flex;
	justify-content: end;
	margin-left: 24rpx;
}

.shop_bottom {
	overflow-x: scroll;
	display: flex;
	margin-top: 25rpx;
	margin-left: 170rpx;
}

.shop_top {
	display: flex;
	justify-content: space-between;
	align-items: center;
}

.shopList {
	display: flex;
	flex-direction: column;
	background: #fff;
	// min-height: 408rpx;
	background: #FFFFFF;
	border-radius: 10rpx;
	padding: 20rpx 0;
	margin-bottom: 20rpx;

	img {
		width: 142rpx;
		height: 146rpx;
		border-radius: 10rpx;
	}

	image {
		width: 142rpx;
		height: 146rpx;
		border-radius: 10rpx;
	}

	.shop_top {
		display: flex;
		justify-content: space-between;
		align-items: center;

		.topLeft {
			display: flex;
			justify-content: end;
			margin-left: 24rpx;

			.shopText {
				display: flex;
				flex-direction: column;
				justify-content: space-between;
				margin-left: 24rpx;
			}

			.shopName {
				font-size: 30rpx;
				font-family: PingFang SC;
				font-weight: 500;
				color: #161415;
			}

			.shopNum,
			.shopMoney {
				font-size: 20rpx;
				font-family: PingFang SC;
				font-weight: 400;
				color: #989898;
			}
		}

		.topRight {
			display: flex;
			flex-direction: column;
			margin-right: 25rpx;

			.school {
				min-width: 87rpx;
				text-align: center;
				height: 29rpx;
				line-height: 29rpx;
				background: #F14500;
				border-radius: 5rpx;
				font-size: 16rpx;
				font-family: PingFang SC;
				font-weight: 400;
				color: #FFFFFF;
			}

			.long {
				margin-top: 50rpx;
				font-size: 20rpx;
				font-family: PingFang SC;
				font-weight: 400;
				color: #989898;
			}
		}
	}

	.shop_bottom {
		overflow-x: scroll;
		display: flex;
		margin-top: 25rpx;
		margin-left: 170rpx;

		.describeContent {
			display: flex;
			flex-direction: column;
			align-items: flex-start;
			justify-content: space-around;
			margin: 0 3px;
			padding: 6rpx;
			min-width: 157rpx;
			height: 186rpx;
			background: #FFFFFF;
			border: 1px solid #F9F9F9;
			border-radius: 10rpx;

			.describe {
				margin-top: 5rpx;
				font-size: 18rpx;
				font-family: PingFang SC;
				font-weight: 500;
				color: #161415;
			}

			.price {
				font-size: 20rpx;
				font-family: PingFang SC;
				font-weight: 500;
				color: #3A3A3A;


				.pri_t {
					margin-left: 8rpx;
					font-size: 18rpx;
					font-family: PingFang SC;
					font-weight: 400;
					text-decoration: line-through;
				}
			}
		}
	}
}

.searchResult {
	width: 100vw;
	height: 100vh;
	background-color: #F9F9F9;
	padding: 0 24rpx;
	border-radius: 10rpx;
	overflow-y: scroll;
}

.tagContent {
	display: flex;
	justify-content: space-between;
	padding: 0 42rpx;
	height: 94rpx;

	.text {
		margin-top: 35rpx;
		font-size: 30rpx;
		font-family: PingFang SC;
		font-weight: 400;
		color: #C3C4C4;
		line-height: 30rpx;
	}
}

.u-mode-light-primary.active {
	color: #F14500;
}

.u-mode-light-primary {
	display: inline-flex;
	justify-content: space-around;
	background: none;
	border: none;
	font-size: 28rpx;
	font-family: PingFang SC;
	font-weight: 500;
	color: #3F3F3F;
	line-height: 70rpx;
}
</style>